<?php

namespace app\admin\app\model;

use plugin\admin\app\model\Base;

/**
 * @property integer $id 主键(主键)
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 * @property integer $card 卡号
 * @property integer $admin_id 管理员id
 * @property integer $serial_number 序列号
 * @property string $start_time 开始时间
 * @property string $end_time 结束时间
 * @property integer $status 状态
 * @property integer $category_id 分类
 */
class Card extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_card';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';


    public function getConfigAttribute($value)
    {
        return $value ? json_decode($value, true) : [
            'publish_min' => 240,
            'publish_max' => 360,
            'is_ai_title' => 1,
            'title' => '',
            'foster_min' => 240,
            'foster_max' => 360,
            'video_min' => 5,
            'video_max' => 20,
            'like_prob' => 50,
            'collect_prob' => 50,
            'follow_prob' => 50,
            'comment_prob' => 50,
            'comment' => '',
        ];
    }

    public function setConfigAttribute($value)
    {
        $this->attributes['config'] = json_encode($value);
    }

    public function setCardAttribute($value)
    {
        $this->attributes['card'] = random_string();
    }

    protected static function booted()
    {
        static::updating(function ($model) {
            unset($model->card);
        });
    }
}
